<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>会员充值信息</title>
<%@include file="../collect/meta.jsp"%>
<link rel="stylesheet" href="css/radius.css" type="text/css"></link>
<link rel="stylesheet" href="css/table.css" type="text/css"></link>
<link rel="stylesheet" href="css/btn-bottom.css" type="text/css"></link>
<script type="text/javascript" src="${ctx}/js/returnTop.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctx }/calender/WdatePicker.js"></script>
</head>
<body lang="zh-cn">
	<div class="wrapper">
		<c:import url="/collect/top.jsp"></c:import>
		<div class="main-container" id="main-container">
			<div class="main-container-inner">
				<c:import url="/collect/left.jsp"></c:import>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li><i class="icon-home home-icon"></i>充值记录</li>
						</ul>
					</div>
					<div class="page-content">
						<div class="row">
							<div class="col-xs-12">
								<div class="alert alert-success">今年充值额：${yearConsume
									}元&nbsp;&nbsp;&nbsp;&nbsp; 本月充值额：${monthConsume
									}元&nbsp;&nbsp;&nbsp;&nbsp; 今日充值额：${dayConsume }元</div>
								<div id="btn-bottom">
									手机号：
									<input type="text"
										name="balance.memberMobile" id="mobile" placeholder="手机号"
										value="${balance.memberMobile }" />
									&nbsp;
									店铺：
									<select id="eaStore" name="balance.shopId">
										<c:choose>
											<c:when test="${not empty shops }">
												<option value="0">全部</option>
											</c:when>
											<c:otherwise>
												<option value="0"></option>
											</c:otherwise>
										</c:choose>
										<c:forEach items="${shops }" var="shop">
											<option value="${shop.id }" <c:if test="${shop.id == balance.shopId}">selected='selected'</c:if>>
												${shop.name}
											</option>
										</c:forEach>
									</select>
									&nbsp;
									充值方式：
									<select id="balType" name="balance.type">
										<option value="0" <c:if test="${balance.type == 0}">selected='selected'</c:if>>全部</option>
										<option value="1" <c:if test="${balance.type == 1}">selected='selected'</c:if>>现金</option>
										<option value="2" <c:if test="${balance.type == 2}">selected='selected'</c:if>>支付宝扫码</option>
									</select>
									&nbsp;
									固定时间：
									<select id="balTime" name="balance.timeType">
										<option value="0" <c:if test="${balance.timeType == 0 }">selected='selected'</c:if> >-- 未选择 --</option>
										<option value="1" <c:if test="${balance.timeType == 1 }">selected='selected'</c:if> >本年</option>
										<option value="2" <c:if test="${balance.timeType == 2 }">selected='selected'</c:if> >本月</option>
										<option value="3" <c:if test="${balance.timeType == 3 }">selected='selected'</c:if> >本周</option>
										<option value="4" <c:if test="${balance.timeType == 4 }">selected='selected'</c:if> >今日</option>
									</select>
									&nbsp;
									<span id="selectedTimeTxt">自选时间：</span>
									<input type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
										style="width:186px;height:30px;" placeholder="开始时间"
										value="${balance.beginTime}" id="balBeginTime">
									<input type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
										style="width:186px;height:30px;" placeholder="结束时间"
										value="${balance.endTime }" id="balEndTime">
									&nbsp;
									<input type="button" class="btn btn-primary radius btn-sm" value="搜索"
										id="oneMemberBtn">
									&nbsp;
									<input type="button" class="btn btn-success radius btn-sm" value="对账导出"
										id="exportCSVBtn">
								</div>
								<table id="table_bug_report"
									class="table table-striped table-bordered table-hover">
									<tr>
										<th>会员手机号</th>
										<th>姓名</th>
										<th>充值方式</th>
										<th>充值金额</th>
										<th>到账金额</th>
										<th>店铺名称</th>
										<th>操作人</th>
										<th>充值时间</th>
									</tr>
									<c:forEach items="${balances}" var="ibalance"
										varStatus="status">
										<tr <c:if test="${status.count%2==0}">bgcolor="#d8e7f0"</c:if>
											<c:if test="${status.count%2!=0}">bgcolor="#ffffff"</c:if>>
											<td><div align="center">${ibalance.memberMobile}</div>
											</td>
											<td>${ibalance.memberName }</td>
											<td>
												<c:choose>
													<c:when test="${ibalance.type == 1 }">现金</c:when>
													<c:when test="${ibalance.type == 2 }">支付宝扫码</c:when>
												</c:choose>
											</td>
											<td>${ibalance.money }</td>
											<td>
												<c:choose>
													<c:when test="${ibalance.type == 1 }">${ibalance.money }</c:when>
													<c:when test="${ibalance.type == 2 }">${ibalance.directPayMoney }</c:when>
												</c:choose>
											</td>
											<td>${ibalance.shopName }</td>
											<td>${ibalance.userName}</td>
											<td>${fn:substring(ibalance.createTime, 0, fn:indexOf(ibalance.createTime, '.')) }</td>
										</tr>
									</c:forEach>
								</table>
								<input type="hidden" id="currentIndex" value="${index }">
								<input type="hidden" id="lastIndex" value="${page }">
								<div class="row" id="page">
									<ul class="pagination">
										<li><a href="javascript:void(0);" id="firstPage">首页</a></li>
										<li class="prev"><a href="javascript:void(0);"
											id="previousPage"> <i class="icon-double-angle-left"></i>
										</a>
										</li>
										<li><a href="javascript:void(0)">${index }</a></li>
										<li><a href="javascript:void(0);" id="nextPage"> <i
												class="icon-double-angle-right"></i> </a>
										</li>
										<li><a href="javascript:void(0);" id="lastPage">末页</a></li>
										<li><a href="javascript:void(0)">共${page}页</a></li>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<a href="#" id="btn-scroll-up"
				class="btn-scroll-up btn btn-sm btn-inverse"
				style="position:fixed;bottom:0;"> <i
				class="icon-double-angle-up icon-only bigger-110"></i> </a>
		</div>
		<div class="push"></div>
	</div>
	<c:import url="/collect/down.jsp"></c:import>
</body>

<script type="text/javascript">
	$(document).ready(function() {
		function selectedTimeShow() {
			if ($("#balTime").val() == 0) {
				$("#balBeginTime").show();
				$("#balEndTime").show();
				$("#selectedTimeTxt").show();
			}else {
				$("#balBeginTime").hide();
				$("#balEndTime").hide();
				$("#selectedTimeTxt").hide();
			}
		}
		
		$("#oneMemberBtn").click(function() {
			watchEnterpriseBalance(1);
		});
		
		$("#eaStore").change(function() {
			watchEnterpriseBalance(1);
		});
		
		$("#balType").change(function() {
			watchEnterpriseBalance(1);
		});
		
		$("#balTime").change(function() {
			watchEnterpriseBalance(1);
		});
		
		// 第一页
		$("#firstPage").click(function() {
			watchEnterpriseBalance(1);
		});

		// 上一页
		$("#previousPage").click(function() {
			var index = $("#currentIndex").val();
			watchEnterpriseBalance(parseInt(index) - parseInt(1));
		});

		// 下一页
		$("#nextPage").click(function() {
			var index = $("#currentIndex").val();
			watchEnterpriseBalance(parseInt(index) + parseInt(1));
		});

		// 最末页
		$("#lastPage").click(function() {
			var index = $("#lastIndex").val();
			watchEnterpriseBalance(index);
		});
		
		$("#balTime").change(function() {
			selectedTimeShow();
		});
		
		function watchEnterpriseBalance(index) {
			var url = "mbalance!watchEnterpriseBalance?index=" + index;
			
			url += "&balance.memberMobile=" + $("#mobile").val();
			url += "&balance.shopId=" + $("#eaStore").val();
			url += "&balance.type=" + $("#balType").val();
			url += "&balance.timeType=" + $("#balTime").val();
			
			var beginTime = $("#balBeginTime").val();
			var endTime = $("#balEndTime").val();
			// 检查时间区间大小
			if (beginTime != null && beginTime != '' && endTime != null && endTime != '') {
				var startTime = new Date(beginTime.replace("-", "/").replace("-", "/"));
				var overTime = new Date(endTime.replace("-", "/").replace("-", "/"));
				if (startTime >= overTime) {
					alert("起始时间不能大于结束时间");
					return false;
				}
			}
			
			url += "&balance.beginTime=" + beginTime;
			url += "&balance.endTime=" + endTime;
			
			window.location.href = url;
		}
		
		$("#exportCSVBtn").click(function() {
			var url = "mbalance!exportBalances?";
			
			url += "balance.memberMobile=" + $("#mobile").val();
			url += "&balance.shopId=" + $("#eaStore").val();
			url += "&balance.type=" + $("#balType").val();
			url += "&balance.timeType=" + $("#balTime").val();
			
			var beginTime = $("#balBeginTime").val();
			var endTime = $("#balEndTime").val();
			// 检查时间区间大小
			if (beginTime != null && beginTime != '' && endTime != null && endTime != '') {
				var startTime = new Date(beginTime.replace("-", "/").replace("-", "/"));
				var overTime = new Date(endTime.replace("-", "/").replace("-", "/"));
				if (startTime >= overTime) {
					alert("起始时间不能大于结束时间");
					return false;
				}
			}
			
			url += "&balance.beginTime=" + beginTime;
			url += "&balance.endTime=" + endTime;
			
			window.location.href = url;
		});
		
		$('.czjl > a').css("color", "red");
		selectedTimeShow();
	});
</script>
</html>